#-*- coding:UTF-8 -*-
#统计各种文件的类型个数
import os
import os 
import os.path 
import shutil 
rootdir='/Users/wesleyxiao/Documents/backup'

# 文件夹根据数量排序
def sort(dicts):
	newDict={}
	newArray =[]
	for item in dicts.items():
		newArray.append(item)
	newArray.sort(lambda x,y:cmp(y[1],x[1]))
	return newArray

#显示各个文件类型的多少，类型
def showFilesFormat(file_list):
	print '文件类型有',str(len(newArray))+'种'
	for item in newArray:
		print "format:" + item[0] +" count:"+str(item[1])
		

#**********程序主逻辑************
filecount = 0
dict=  {} 
for parent,dirnames,filenames in os.walk(rootdir):
	for filename in filenames:
		sufix = os.path.splitext(filename)[1][1:]
		filecount+=1
		# print "sufix:",sufix
		if dict.has_key(sufix):
			dict[sufix] += 1
		else:
			dict[sufix]=1

print '共有',str(filecount),'个文件'
newArray=sort(dict)
showFilesFormat(newArray)